﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KTV项目
{
    class Bestdao
    {
        private string ku = "Data Source=www.xiao.com;Initial Catalog=fanChengKTV;Persist Security Info=True;User ID=fancheng;Password=moke0810";
        //返回数据库中返回的数据条数
        public int scalar(string sql) {
            SqlConnection conn = new SqlConnection(ku);
            conn.Open();
            SqlCommand cha = new SqlCommand(sql,conn);
            int he =Convert.ToInt32(cha.ExecuteScalar());
            return he;
        }
        //返回数据库中受影响的行数
        public int query(string sql) {
            SqlConnection conn = new SqlConnection(ku);
            conn.Open();
            SqlCommand cha = new SqlCommand(sql,conn);
            int he = cha.ExecuteNonQuery();
            return he;
        }
        //返回数据库查询的数据并创建临时表再返回此表
        public DataTable table(string sql) {
            DataSet set = new DataSet();
            SqlConnection conn = new SqlConnection(ku);
            SqlDataAdapter ad = new SqlDataAdapter(sql,conn);
            ad.Fill(set,"gequ");
            return set.Tables["gequ"];
        }
        //返回数据库查询到的对应的数据
        public string Scal(string sql)
        {
            SqlConnection conn = new SqlConnection(ku);
            conn.Open();
            SqlCommand cha = new SqlCommand(sql, conn);
            string he=Convert.ToString(cha.ExecuteScalar());
            return he;
        }
    }
}
